using HKB.Common;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
namespace HKB.Web.DataHelper
{
	public class CM_ProductsBll
	{
		private static CM_ProductsBll _instance = null;
		private Conn conn = null;
		public static CM_ProductsBll instance
		{
			get
			{
				if (CM_ProductsBll._instance == null)
				{
					CM_ProductsBll._instance = new CM_ProductsBll(new Conn());
				}
				return CM_ProductsBll._instance;
			}
		}
		public CM_ProductsBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public CM_ProductsBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetProductAll()
		{
			string arg = "ProductID,ProductName,ProductImageUrl,ProductType,CurrentPrice,StandPrice,BeginDate";
			string arg2 = "IsApprove=1 and EnableSale=1 and EnableSingleSell=1 and Stocks>0 and IsPageElite=1";
			string sql = string.Format("select top 12 {0}  from HLShop_Product p where {1} order by p.ProductID desc", arg, arg2);
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetProductAllByProvince(string Province)
		{
			string commandText = "select top 16 * from HLShop_Product p   where IsApprove=1 and EnableSale=1 and EnableSingleSell=1 and Stocks>0 and IsElite=1 and Province =@Province order by p.ProductID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Province", DbType.String, Province);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetProductAllByCity(string city)
		{
			string commandText = "select top 16 * from HLShop_Product p   where IsApprove=1 and EnableSale=1 and EnableSingleSell=1 and Stocks>0 and IsElite=1 and City =@City order by p.ProductID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@City", DbType.String, city);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetProductAllByArea(string Area)
		{
			string commandText = "select top 16 * from HLShop_Product p   where IsApprove=1 and EnableSale=1 and EnableSingleSell=1 and Stocks>0 and IsElite=1 and Area =@Area order by p.ProductID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Area", DbType.String, Area);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetShopAll()
		{
			string sql = "select top 25 * from HLShop_Shop where ShopStatus=1 order by ShopID ASC";
			return this.conn.GetDataTable(sql);
		}
		public DataTable GetShopAllByProvince(string Province)
		{
			string commandText = "select top 21 * from HLShop_Shop where Province=@Province order by ShopID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Province", DbType.String, Province);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetShopAllByCity(string City)
		{
			string commandText = "select top 21 * from HLShop_Shop where City=@City order by ShopID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@City", DbType.String, City);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetShopAllByArea(string Area)
		{
			string commandText = "select top 21 * from HLShop_Shop where Area=@Area order by ShopID desc";
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@Area", DbType.String, Area);
			return this.conn.GetDataTable(commandText, new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetShopByClassID(int ClassID, int pagesize, int PageIndex)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("select top {0} ", pagesize);
			stringBuilder.Append(" (ROW_NUMBER() OVER (ORDER BY ShopID desc))-1 rowid,* ");
			stringBuilder.Append(" from HLShop_Shop where ShopCategoryID=@ClassID  and isnull(logopath,'')<>'' ");
			stringBuilder.AppendFormat(" and shopid not in(select top {0} shopid from HLShop_Shop where ShopCategoryID=@ClassID and isnull(logopath,'')<>'' order by ShopID desc) ", (PageIndex - 1) * pagesize);
			stringBuilder.Append(" order by ShopID desc ");
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ClassID", DbType.Int32, ClassID);
			return this.conn.GetDataTable(stringBuilder.ToString(), new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetShopInfoByClassID(int ClassID, int pagesize, int PageIndex)
		{
			StringBuilder stringBuilder = new StringBuilder();
			string text = string.Format(" ShopCategoryID=@ClassID  and isnull(logopath,'')<>'' and ShopStatus=1 ", new object[0]);
			string value = "ShopName,LogoPath,ShopImageUrl,ShopID,ShopOperatorItem";
			string text2 = " order by RecommendShop,ShopID desc ";
			stringBuilder.AppendFormat("select top {0} ", pagesize);
			stringBuilder.Append(" (ROW_NUMBER() OVER (ORDER BY ShopID desc))-1 rowid, ");
			stringBuilder.Append(value);
			stringBuilder.AppendFormat(" from HLShop_Shop where {0} ", text);
			stringBuilder.AppendFormat(" and shopid not in(select top {0} shopid from HLShop_Shop where {1} ) ", (PageIndex - 1) * pagesize, text, text2);
			stringBuilder.AppendFormat(text2, new object[0]);
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ClassID", DbType.Int32, ClassID);
			return this.conn.GetDataTable(stringBuilder.ToString(), new IDbDataParameter[]
			{
				dbDataParameter
			});
		}
		public DataTable GetProClassByClassID(int ClassID)
		{
			return this.conn.GetDataTable("select dbo.GetClassParentPath(ClassID) as ClassName from  [HLShop_Class] where ClassID=" + ClassID);
		}
		public object[] GetAddProduct(ProductModels models)
		{
			SqlParameter[] array = new SqlParameter[]
			{
				this.conn.CreateSQlParameter("@ShopID", SqlDbType.Int, models.ShopID, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@SalerID", SqlDbType.Int, models.SalerID, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ClassID", SqlDbType.Int, models.ClassID, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductName", SqlDbType.VarChar, models.ProductName, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductIntro", SqlDbType.VarChar, models.ProductIntro, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductImageUrl", SqlDbType.VarChar, models.ProductImageUrl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductSmallImageUrl", SqlDbType.VarChar, models.ProductSmallImageUrl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductType", SqlDbType.Int, models.ProductType, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@StandPrice", SqlDbType.Decimal, models.StandPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@CurrentPrice", SqlDbType.Decimal, models.CurrentPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Stocks", SqlDbType.Int, models.Stocks, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@BeginDate", SqlDbType.DateTime, models.BeginDate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EndDate", SqlDbType.DateTime, models.EndDate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@UpdateTime", SqlDbType.DateTime, models.UpdateTime, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@CreateTime", SqlDbType.DateTime, models.CreateTime, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Keyword", SqlDbType.VarChar, models.Keyword, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Inputer", SqlDbType.VarChar, models.Inputer, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Province", SqlDbType.VarChar, models.Province, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@City", SqlDbType.VarChar, models.City, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Area", SqlDbType.VarChar, models.Area, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@IsElite", SqlDbType.Int, models.IsElite, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@DeliverPayType", SqlDbType.Int, models.DeliverPayType, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ValidDay", SqlDbType.Int, models.ValidDay, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EnableSingleSell", SqlDbType.Int, models.EnableSingleSell, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Description", SqlDbType.VarChar, models.Description, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Goods_lbl", SqlDbType.VarChar, models.Goods_lbl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductStandard", SqlDbType.Int, models.ProductStandard, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@DeliverType", SqlDbType.Int, models.DeliverType, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@goods_serial", SqlDbType.VarChar, models.goods_serial, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamName", SqlDbType.VarChar, models.TeamName, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNum", SqlDbType.Int, models.TeamNum, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TempSubScriptionRate", SqlDbType.Int, models.TempSubScriptionRate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice1", SqlDbType.Decimal, models.TeamPrice1, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber1", SqlDbType.Int, models.TeamNumber1, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice2", SqlDbType.Decimal, models.TeamPrice2, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber2", SqlDbType.Int, models.TeamNumber2, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice3", SqlDbType.Decimal, models.TeamPrice3, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber3", SqlDbType.Int, models.TeamNumber3, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice4", SqlDbType.Decimal, models.TeamPrice4, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber4", SqlDbType.Int, models.TeamNumber4, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice5", SqlDbType.Decimal, models.TeamPrice5, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber5", SqlDbType.Int, models.TeamNumber5, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ImcrementPrice", SqlDbType.Decimal, models.ImcrementPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EnableSale", SqlDbType.Int, models.EnableSale, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@AuctionStartPrice", SqlDbType.Decimal, models.AuctionStartPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@PartPrice", SqlDbType.Decimal, 0, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@IsApprove", SqlDbType.Int, models.IsApprove, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Attributes", SqlDbType.VarChar, models.Attributes, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_title", SqlDbType.VarChar, models.Prc_sp_title, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_value", SqlDbType.VarChar, models.Prc_sp_value, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_valueDetail", SqlDbType.VarChar, models.Prc_sp_valueDetail, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Identity", SqlDbType.Int, 0, ParameterDirection.Output),
				this.conn.CreateSQlParameter("@AlarmNum", SqlDbType.Int, models.AlarmNum, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@NeedPresentExp", SqlDbType.Int, models.NeedPresentExp, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@IsDeleted", SqlDbType.Int, models.IsDeleted, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@CustomPrice", SqlDbType.VarChar, models.CustomPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@PUnit", SqlDbType.VarChar, models.PUnit, ParameterDirection.Input)
			};
			int num = this.conn.Execute("pro_Insert_Goods", array);
			object[] result;
			if (num > 0)
			{
				result = new object[]
				{
					num,
					array[51].Value
				};
			}
			else
			{
				result = null;
			}
			return result;
		}
		public bool GetProductImg(int ProductID, int SalerID, string ImgPath1, string ImgPath2, string ImgPath3, string ImgPath4, string Imgpath5)
		{
			string commandText = "INSERT INTO HLShop_ProductImg(ProductID,SalerID,ImgPath1,ImgPath2,ImgPath3,ImgPath4,Imgpath5) VALUES(@ProductID,@SalerID,@ImgPath1,@ImgPath2,@ImgPath3,@ImgPath4,@Imgpath5)";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ProductID", DbType.Int32, ProductID),
				this.conn.CreateParameter("@SalerID", DbType.Int32, SalerID),
				this.conn.CreateParameter("@ImgPath1", DbType.String, ImgPath1),
				this.conn.CreateParameter("@ImgPath2", DbType.String, ImgPath2),
				this.conn.CreateParameter("@ImgPath3", DbType.String, ImgPath3),
				this.conn.CreateParameter("@ImgPath4", DbType.String, ImgPath4),
				this.conn.CreateParameter("@Imgpath5", DbType.String, Imgpath5)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
		public DataTable GetProductByProductID(int productID)
		{
			return this.conn.GetDataTable("select * from dbo.HLShop_Product where ProductID=" + productID);
		}
		public DataTable GetProdcutImageByProductID(int productID)
		{
			return this.conn.GetDataTable("select * from HLShop_ProductImg where ProductID=" + productID);
		}
		public bool GetUpdateProduct(ProductModels models)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				this.conn.CreateSQlParameter("@ProductID", SqlDbType.Int, models.ProductID, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductName", SqlDbType.VarChar, models.ProductName, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductIntro", SqlDbType.VarChar, models.ProductIntro, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductImageUrl", SqlDbType.VarChar, models.ProductImageUrl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductSmallImageUrl", SqlDbType.VarChar, models.ProductSmallImageUrl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@StandPrice", SqlDbType.Decimal, models.StandPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@CurrentPrice", SqlDbType.Decimal, models.CurrentPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Stocks", SqlDbType.Int, models.Stocks, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@BeginDate", SqlDbType.DateTime, models.BeginDate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EndDate", SqlDbType.DateTime, models.EndDate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@UpdateTime", SqlDbType.DateTime, models.UpdateTime, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Keyword", SqlDbType.VarChar, models.Keyword, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Province", SqlDbType.VarChar, models.Province, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@City", SqlDbType.VarChar, models.City, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Area", SqlDbType.VarChar, models.Area, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@IsElite", SqlDbType.Int, models.IsElite, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@DeliverPayType", SqlDbType.Int, models.DeliverPayType, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ValidDay", SqlDbType.Int, models.ValidDay, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EnableSingleSell", SqlDbType.Int, models.EnableSingleSell, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Description", SqlDbType.VarChar, models.Description, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Goods_lbl", SqlDbType.VarChar, models.Goods_lbl, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ProductStandard", SqlDbType.Int, models.ProductStandard, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@DeliverType", SqlDbType.Int, models.DeliverType, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@goods_serial", SqlDbType.VarChar, models.goods_serial, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamName", SqlDbType.VarChar, models.TeamName, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNum", SqlDbType.Int, models.TeamNum, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TempSubScriptionRate", SqlDbType.Int, models.TempSubScriptionRate, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice1", SqlDbType.Decimal, models.TeamPrice1, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber1", SqlDbType.Int, models.TeamNumber1, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice2", SqlDbType.Decimal, models.TeamPrice2, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber2", SqlDbType.Int, models.TeamNumber2, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice3", SqlDbType.Decimal, models.TeamPrice3, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber3", SqlDbType.Int, models.TeamNumber3, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice4", SqlDbType.Decimal, models.TeamPrice4, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber4", SqlDbType.Int, models.TeamNumber4, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamPrice5", SqlDbType.Decimal, models.TeamPrice5, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@TeamNumber5", SqlDbType.Int, models.TeamNumber5, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@ImcrementPrice", SqlDbType.Decimal, models.ImcrementPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@AuctionStartPrice", SqlDbType.Decimal, models.AuctionStartPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_title", SqlDbType.VarChar, models.Prc_sp_title, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_value", SqlDbType.VarChar, models.Prc_sp_value, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@prc_sp_valueDetail", SqlDbType.VarChar, models.Prc_sp_valueDetail, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@Attributes", SqlDbType.VarChar, models.Attributes, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@AlarmNum", SqlDbType.Int, models.AlarmNum, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@NeedPresentExp", SqlDbType.Int, models.NeedPresentExp, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@IsDeleted", SqlDbType.Int, models.IsDeleted, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@CustomPrice", SqlDbType.VarChar, models.CustomPrice, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@PUnit", SqlDbType.VarChar, models.PUnit, ParameterDirection.Input),
				this.conn.CreateSQlParameter("@EnableSale", SqlDbType.Int, models.EnableSale, ParameterDirection.Input)
			};
			int num = this.conn.Execute("pro_update_Goods", parameters);
			return num == 1;
		}
		public bool GetUpadateProductImg(int ImgID, string ImgPath1, string ImgPath2, string ImgPath3, string ImgPath4, string Imgpath5)
		{
			string commandText = "UPDATE HLShop_ProductImg SET ImgPath1 = @ImgPath1, ImgPath2 = @ImgPath2,ImgPath3 = @ImgPath3, ImgPath4 = @ImgPath4, Imgpath5 = @Imgpath5 WHERE ImgID=@ImgID";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@ImgID", DbType.Int32, ImgID),
				this.conn.CreateParameter("@ImgPath1", DbType.String, ImgPath1),
				this.conn.CreateParameter("@ImgPath2", DbType.String, ImgPath2),
				this.conn.CreateParameter("@ImgPath3", DbType.String, ImgPath3),
				this.conn.CreateParameter("@ImgPath4", DbType.String, ImgPath4),
				this.conn.CreateParameter("@Imgpath5", DbType.String, Imgpath5)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
	}
}
